/*
 * File: Controller.h
 *
 * Code generated for Simulink model 'Controller'.
 *
 * Model version                  : 1.157
 * Simulink Coder version         : 8.1 (R2011b) 08-Jul-2011
 * TLC version                    : 8.1 (Jul  9 2011)
 * C/C++ source code generated on : Sat Jan 28 13:43:40 2012
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Texas Instruments->C2000
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#ifndef RTW_HEADER_Controller_h_
#define RTW_HEADER_Controller_h_
#ifndef Controller_COMMON_INCLUDES_
# define Controller_COMMON_INCLUDES_
#include <string.h>
#include "rtwtypes.h"
#endif                                 /* Controller_COMMON_INCLUDES_ */

#include "Controller_types.h"

/* Macros for accessing real-time model data structure */
#ifndef rtmGetErrorStatus
# define rtmGetErrorStatus(rtm)        ((rtm)->errorStatus)
#endif

#ifndef rtmSetErrorStatus
# define rtmSetErrorStatus(rtm, val)   ((rtm)->errorStatus = (val))
#endif

/* Block signals (auto storage) */
typedef struct {
  real32_T Saturation;                 /* '<S11>/Saturation' */
  real32_T Saturation_g;               /* '<S9>/Saturation' */
  real32_T Saturation_i;               /* '<S7>/Saturation' */
  int32_T PosPID;                      /* '<S1>/Chart' */
  int32_T SpeedPID;                    /* '<S1>/Chart' */
  int32_T CurrPID;                     /* '<S1>/Chart' */
  int32_T SpOverride;                  /* '<S1>/Chart' */
  int32_T Enable;                      /* '<S1>/Chart' */
  int32_T State;                       /* '<S1>/Chart' */
} BlockIO_Controller;

/* Block states (auto storage) for system '<Root>' */
typedef struct {
  real32_T Integrator_DSTATE;          /* '<S11>/Integrator' */
  real32_T Filter_DSTATE;              /* '<S11>/Filter' */
  real32_T Integrator_DSTATE_p;        /* '<S9>/Integrator' */
  real32_T Integrator_DSTATE_f;        /* '<S7>/Integrator' */
  uint32_T presentTicks;               /* '<S1>/Chart' */
  uint32_T elapsedTicks;               /* '<S1>/Chart' */
  uint32_T previousTicks;              /* '<S1>/Chart' */
  uint16_T temporalCounter_i1;         /* '<S1>/Chart' */
  uint8_T is_active_c1_Controller;     /* '<S1>/Chart' */
  uint8_T is_c1_Controller;            /* '<S1>/Chart' */
  uint8_T is_On;                       /* '<S1>/Chart' */
  boolean_T PositionCtrl_MODE;         /* '<S1>/PositionCtrl' */
  boolean_T SpeedCtrl_MODE;            /* '<S1>/SpeedCtrl' */
  boolean_T CurrentCtrl_MODE;          /* '<S1>/CurrentCtrl' */
} D_Work_Controller;

/* External inputs (root inport signals with auto storage) */
typedef struct {
  real32_T Iscaled;                    /* '<Root>/CurrentU' */
  real32_T InRef;                      /* '<Root>/InRef' */
  int32_T Locked;                      /* '<Root>/Locked' */
  int32_T Mode;                        /* '<Root>/Mode' */
  real32_T PositionN;                  /* '<Root>/PositionN' */
  real32_T OmegaRadS;                  /* '<Root>/OmegaRadS' */
} ExternalInputs_Controller;

/* External outputs (root outports fed by signals with auto storage) */
typedef struct {
  real32_T DutyU;                      /* '<Root>/DutyU' */
  int32_T Enable;                      /* '<Root>/Enable' */
  int32_T State;                       /* '<Root>/State' */
} ExternalOutputs_Controller;

/* Parameters (auto storage) */
struct Parameters_Controller_ {
  real32_T Constant_Value;             /* Computed Parameter: Constant_Value
                                        * Referenced by: '<S1>/Constant'
                                        */
  real32_T Out1_Y0;                    /* Computed Parameter: Out1_Y0
                                        * Referenced by: '<S3>/Out1'
                                        */
  real32_T ProportionalGain_Gain;      /* Computed Parameter: ProportionalGain_Gain
                                        * Referenced by: '<S7>/Proportional Gain'
                                        */
  real32_T Integrator_gainval;         /* Computed Parameter: Integrator_gainval
                                        * Referenced by: '<S7>/Integrator'
                                        */
  real32_T Integrator_IC;              /* Computed Parameter: Integrator_IC
                                        * Referenced by: '<S7>/Integrator'
                                        */
  real32_T Saturation_UpperSat;        /* Computed Parameter: Saturation_UpperSat
                                        * Referenced by: '<S7>/Saturation'
                                        */
  real32_T Saturation_LowerSat;        /* Computed Parameter: Saturation_LowerSat
                                        * Referenced by: '<S7>/Saturation'
                                        */
  real32_T IntegralGain_Gain;          /* Computed Parameter: IntegralGain_Gain
                                        * Referenced by: '<S7>/Integral Gain'
                                        */
  real32_T Constant_Value_f;           /* Computed Parameter: Constant_Value_f
                                        * Referenced by: '<S7>/Constant'
                                        */
  real32_T Out1_Y0_d;                  /* Computed Parameter: Out1_Y0_d
                                        * Referenced by: '<S4>/Out1'
                                        */
  real32_T ProportionalGain_Gain_c;    /* Computed Parameter: ProportionalGain_Gain_c
                                        * Referenced by: '<S9>/Proportional Gain'
                                        */
  real32_T Integrator_gainval_a;       /* Computed Parameter: Integrator_gainval_a
                                        * Referenced by: '<S9>/Integrator'
                                        */
  real32_T Integrator_IC_k;            /* Computed Parameter: Integrator_IC_k
                                        * Referenced by: '<S9>/Integrator'
                                        */
  real32_T Saturation_UpperSat_e;      /* Computed Parameter: Saturation_UpperSat_e
                                        * Referenced by: '<S9>/Saturation'
                                        */
  real32_T Saturation_LowerSat_j;      /* Computed Parameter: Saturation_LowerSat_j
                                        * Referenced by: '<S9>/Saturation'
                                        */
  real32_T IntegralGain_Gain_e;        /* Computed Parameter: IntegralGain_Gain_e
                                        * Referenced by: '<S9>/Integral Gain'
                                        */
  real32_T Constant_Value_k;           /* Computed Parameter: Constant_Value_k
                                        * Referenced by: '<S9>/Constant'
                                        */
  real32_T Out1_Y0_du;                 /* Computed Parameter: Out1_Y0_du
                                        * Referenced by: '<S5>/Out1'
                                        */
  real32_T ProportionalGain_Gain_ca;   /* Computed Parameter: ProportionalGain_Gain_ca
                                        * Referenced by: '<S11>/Proportional Gain'
                                        */
  real32_T Integrator_gainval_f;       /* Computed Parameter: Integrator_gainval_f
                                        * Referenced by: '<S11>/Integrator'
                                        */
  real32_T Integrator_IC_j;            /* Computed Parameter: Integrator_IC_j
                                        * Referenced by: '<S11>/Integrator'
                                        */
  real32_T DerivativeGain_Gain;        /* Computed Parameter: DerivativeGain_Gain
                                        * Referenced by: '<S11>/Derivative Gain'
                                        */
  real32_T Filter_gainval;             /* Computed Parameter: Filter_gainval
                                        * Referenced by: '<S11>/Filter'
                                        */
  real32_T Filter_IC;                  /* Computed Parameter: Filter_IC
                                        * Referenced by: '<S11>/Filter'
                                        */
  real32_T FilterCoefficient_Gain;     /* Computed Parameter: FilterCoefficient_Gain
                                        * Referenced by: '<S11>/Filter Coefficient'
                                        */
  real32_T Saturation_UpperSat_ef;     /* Computed Parameter: Saturation_UpperSat_ef
                                        * Referenced by: '<S11>/Saturation'
                                        */
  real32_T Saturation_LowerSat_k;      /* Computed Parameter: Saturation_LowerSat_k
                                        * Referenced by: '<S11>/Saturation'
                                        */
  real32_T IntegralGain_Gain_a;        /* Computed Parameter: IntegralGain_Gain_a
                                        * Referenced by: '<S11>/Integral Gain'
                                        */
  real32_T Constant_Value_g;           /* Computed Parameter: Constant_Value_g
                                        * Referenced by: '<S11>/Constant'
                                        */
  real32_T ALimit_UpperSat;            /* Computed Parameter: ALimit_UpperSat
                                        * Referenced by: '<S6>/3A Limit'
                                        */
  real32_T ALimit_LowerSat;            /* Computed Parameter: ALimit_LowerSat
                                        * Referenced by: '<S6>/3A Limit'
                                        */
  real32_T uALimit_UpperSat;           /* Computed Parameter: uALimit_UpperSat
                                        * Referenced by: '<S6>/0.8A Limit'
                                        */
  real32_T uALimit_LowerSat;           /* Computed Parameter: uALimit_LowerSat
                                        * Referenced by: '<S6>/0.8A Limit'
                                        */
  real32_T PosLimiter_UpperSat;        /* Computed Parameter: PosLimiter_UpperSat
                                        * Referenced by: '<S1>/PosLimiter'
                                        */
  real32_T PosLimiter_LowerSat;        /* Computed Parameter: PosLimiter_LowerSat
                                        * Referenced by: '<S1>/PosLimiter'
                                        */
};

/* Real-time Model Data Structure */
struct RT_MODEL_Controller {
  const char_T * volatile errorStatus;

  /*
   * Timing:
   * The following substructure contains information regarding
   * the timing information for the model.
   */
  struct {
    uint32_T clockTick0;
    uint32_T clockTickH0;
  } Timing;
};

/* Class declaration for model Controller */
class ControllerModelClass {
  /* public data and function members */
 public:
  /* External inputs */
  ExternalInputs_Controller Controller_U;

  /* External outputs */
  ExternalOutputs_Controller Controller_Y;

  /* Model entry point functions */

  /* model initialize function */
  void initialize();

  /* model step function */
  void step();

  /* model terminate function */
  void terminate();

  /* Constructor */
  ControllerModelClass();

  /* Destructor */
  ~ControllerModelClass();

  /* Real-Time Model get method */
  RT_MODEL_Controller * getRTM() const;

  /* private data and function members */
 private:
  /* Tunable parameters */
  Parameters_Controller Controller_P;

  /* Block signals */
  BlockIO_Controller Controller_B;

  /* Block states */
  D_Work_Controller Controller_DWork;

  /* Real-Time Model */
  RT_MODEL_Controller Controller_M_;

  /* Real-Time Model pointer */
  RT_MODEL_Controller *Controller_M;
};

/*-
 * The generated code includes comments that allow you to trace directly
 * back to the appropriate location in the model.  The basic format
 * is <system>/block_name, where system is the system number (uniquely
 * assigned by Simulink) and block_name is the name of the block.
 *
 * Note that this particular code originates from a subsystem build,
 * and has its own system numbers different from the parent model.
 * Refer to the system hierarchy for this subsystem below, and use the
 * MATLAB hilite_system command to trace the generated code back
 * to the parent model.  For example,
 *
 * hilite_system('servo/Controller')    - opens subsystem servo/Controller
 * hilite_system('servo/Controller/Kp') - opens and selects block Kp
 *
 * Here is the system hierarchy for this model
 *
 * '<Root>' : 'servo'
 * '<S1>'   : 'servo/Controller'
 * '<S2>'   : 'servo/Controller/Chart'
 * '<S3>'   : 'servo/Controller/CurrentCtrl'
 * '<S4>'   : 'servo/Controller/PositionCtrl'
 * '<S5>'   : 'servo/Controller/SpeedCtrl'
 * '<S6>'   : 'servo/Controller/Subsystem'
 * '<S7>'   : 'servo/Controller/CurrentCtrl/PID Controller'
 * '<S8>'   : 'servo/Controller/CurrentCtrl/PID Controller/Clamping circuit'
 * '<S9>'   : 'servo/Controller/PositionCtrl/PID Controller2'
 * '<S10>'  : 'servo/Controller/PositionCtrl/PID Controller2/Clamping circuit'
 * '<S11>'  : 'servo/Controller/SpeedCtrl/PID Controller1'
 * '<S12>'  : 'servo/Controller/SpeedCtrl/PID Controller1/Clamping circuit'
 */
#endif                                 /* RTW_HEADER_Controller_h_ */

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
